package com.zxc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zxc.dao.SalChanceMapper;
import com.zxc.entity.SalChance;
import com.zxc.service.SalChanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service
public class SalChanceServiceImpl extends ServiceImpl<SalChanceMapper, SalChance> implements SalChanceService {

    @Autowired
    private SalChanceMapper salChanceMapper;

    @Override
    public List<SalChance> getSalChanceListByCondition(int skipCounts, Integer pageSize) {
        List<SalChance> salChanceList = salChanceMapper.getSalChanceListByCondition(skipCounts,pageSize);
        return salChanceList;
    }


    @Override
    public int selectCountSalChanceForMarketingByChcDueIds() {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.ne("chc_due_id",0);
        int total = salChanceMapper.selectCount(queryWrapper);
        return total;
    }

    @Override
    public int selectCountSalChanceForMarketingByChcDueId() {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("chc_due_id",0);
        int total = salChanceMapper.selectCount(queryWrapper);
        return total;
    }

    @Override
    public SalChance selectSalChanceBychcId(Integer chcId) {
        SalChance salChance = salChanceMapper.selectById(chcId);
        return salChance;
    }

    @Override
    public int updateSalChanceByChcId(SalChance salChance) {
        int result = salChanceMapper.updateById(salChance);
        return result;
    }

    @Override
    @Transactional
    public int delete(Integer[] chcIds) {
        List<Integer> chcIdList = new ArrayList<>();
        for (Integer chcId : chcIds){
           chcIdList.add(chcId);
        }
        int result = salChanceMapper.deleteBatchIds(chcIdList);
        return result;
    }


    @Override
    @Transactional
    public int saveSalChance(SalChance salChance) {
        int result = salChanceMapper.insert(salChance);
        return result;
    }

    @Override
    public List<SalChance> getSalChanceListByConditionByStatus(int skipCounts, Integer pageSize, String sysUserName) {
        List<SalChance> salChanceList = salChanceMapper.getSalChanceListByConditionByStatus(skipCounts,pageSize,sysUserName);
        return salChanceList;
    }

    @Override
    public List<SalChance> getAllSalChanceList(int skipCounts, Integer pageSize) {
        List<SalChance> salChanceList = salChanceMapper.getAllSalChanceList(skipCounts,pageSize);
        return salChanceList;
    }
}
